//
//  GYTaskHeadView.m
//  LockManagement
//
//  Created by 丁燕春 on 2018/7/28.
//  Copyright © 2018年 yunjiazhineng. All rights reserved.
//

#import "GYTaskHeadView.h"
#import "UITextField+GYCursorPosition.h"

@interface GYTaskHeadView()

@property (weak, nonatomic) IBOutlet UITextField *searchTF;
@property (weak, nonatomic) IBOutlet UIButton *searchBtn;
@property (strong, nonatomic) IBOutletCollection(UIButton) NSArray *taskStateBtns;

@property (strong, nonatomic) IBOutletCollection(UIButton) NSArray *taskTypeBtns;
@property (weak, nonatomic) IBOutlet UILabel *markLable;


@end


@implementation GYTaskHeadView


+ (instancetype)shareView {
    return [[[NSBundle mainBundle] loadNibNamed:NSStringFromClass(self) owner:nil options:nil] firstObject];
}

- (void)awakeFromNib {
    [super awakeFromNib];
    //初始化
    //设置属性
    self.searchTF.CursorPosition = 30;
    self.searchTF.layer.cornerRadius = 20;
    self.searchTF.layer.borderWidth = 1;
    self.searchTF.layer.borderColor = BackGroundColor.CGColor;
    
    self.searchBtn.layer.cornerRadius = 5;
    self.searchBtn.layer.borderWidth = 1;
    self.searchBtn.layer.borderColor = BackGroundColor.CGColor;
    
    [self setBtn:2 WithBtns:self.taskStateBtns];
    [self setBtn:1 WithBtns:self.taskTypeBtns];
}

- (CGFloat)ViewHeight {
    return CGRectGetMaxY(self.markLable.frame);
}

- (IBAction)taskStateBtnClick:(UIButton *)sender {
    [self setBtn:sender.tag WithBtns:self.taskStateBtns];
    //2  3  0
    //1  3  2
    NSString *state = sender.tag == 1 ? @"0" : @"1";
    self.updateTaskListToTaskStateCallBack(state);
}

- (IBAction)taskTypeBtnClick:(UIButton *)sender {
    [self setBtn:sender.tag WithBtns:self.taskTypeBtns];
    NSString *type = sender.tag == 1 ? @"2" : (sender.tag == 2 ? @"0" : @"3");
    self.updateTaskListToTaskTypeCallBack(type);
}

/**
 搜索按钮点击事件

 @param sender <#sender description#>
 */
- (IBAction)searchBtnClick:(UIButton *)sender {
    self.searchTaskCallBack(self.searchTF.text);
}

/**
设置按钮的颜色属性

 @param index 按钮的tag值
 @param btns 按钮集合
 */
- (void)setBtn:(NSInteger)index WithBtns:(NSArray *)btns {
    for (UIButton *btn in btns) {
        [btn setTitleColor:btn.tag == index ? BackGroundColor : HEXColor(0x8F8F8F) forState:UIControlStateNormal];
    }
}











@end
